package ${controllerUrl};

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import ${entityUrl}.${entityName};
import ${serviceUrl}.${entityName}Service;
import ${serviceUrl}.CommonCurdService;
import ${commonUrl}.CommonCurdResultBean;
import ${commonUrl}.CommonCurdPageBean;
import ${commonUrl}.MulTableQuery;

/**
 * filename:${entityName}Controller ${createTime}
 * project ${project}  ${version}
 * Copyright(c) 2019 ${author} Co. Ltd.
 *
 * <p>说明： ${entityComment} API接口层</P>
 * version: ${version}
 * @author : ${author}
 * 
 * Modification History:
 * Date         	Author          Version          Description
 *---------------------------------------------------------------*
 * ${createTime}     ${author}    	${version}        initialize
 */
@Api(tags = "${entityComment} 接口(API)",value="${entityName}实体类接口" )
@RestController
@RequestMapping("/${objectName}")
public class ${entityName}Controller extends CommonCurdController<${entityName}>{

    private  Logger logger=LogManager.getLogger(this.getClass());

    private final ${entityName}Service ${objectName}Service;
    private final CommonCurdService commonCurdService;

    @Autowired
    public ${entityName}Controller(${entityName}Service ${objectName}Service,CommonCurdService commonCurdService) {
        super(commonCurdService);
        this.commonCurdService = commonCurdService;
        this.${objectName}Service = ${objectName}Service;
    }

    @ApiOperation(value = "插入属性不为空的数据方法", notes = "接口备注")
    @PostMapping(value = "/insertOne")
    public CommonCurdResultBean<Void> insertOne(@RequestBody ${entityName} value) {
        CommonCurdResultBean<Void> resultBean = new CommonCurdResultBean<>(true, "");
        ${objectName}Service.insertOne(value);
        return resultBean;
    }

    @ApiOperation(value = "根据id删除对象", notes = "接口备注")
    @PostMapping(value = "/deleteById")
    public CommonCurdResultBean<Void> deleteById(@RequestBody ${entityName} value) {
        CommonCurdResultBean<Void> resultBean = new CommonCurdResultBean<>(true, "");
        ${objectName}Service.deleteById(value);
        return resultBean;
    }

    @ApiOperation(value = "根据id更新对象", notes = "接口备注")
    @PostMapping(value = "/updateById")
    public CommonCurdResultBean<Void> updateById(@RequestBody ${entityName} value) {
        CommonCurdResultBean<Void> resultBean = new CommonCurdResultBean<>(true, "");
        ${objectName}Service.updateById(value);
        return resultBean;
    }

    @ApiOperation(value = "根据id查询对象", notes = "接口备注")
    @PostMapping(value = "/selectById")
    public CommonCurdResultBean<${entityName}> selectById(@RequestBody ${entityName} value) {
        CommonCurdResultBean<${entityName}> resultBean = new CommonCurdResultBean<>(true, "");
        resultBean.setObject(${objectName}Service.selectById(value));
        return resultBean;
    }

    @ApiOperation(value = "根据查询条件查询数据【分页】", notes = "查询接口备注")
    @PostMapping(value = "/queryByConditionPage")
    public CommonCurdResultBean<MulTableQuery.Pagination<${entityName}>> queryByConditionPage(@RequestBody CommonCurdPageBean<${entityName}> pageBean) {
        CommonCurdResultBean<MulTableQuery.Pagination<${entityName}>> resultBean = new CommonCurdResultBean<>(true, "");
        resultBean.setObject((MulTableQuery.Pagination<${entityName}>) ${objectName}Service.queryByConditionPage(pageBean));
        return resultBean;
    }

    @ApiOperation(value = "根据查询条件查询数据【不分页】", notes = "查询接口备注")
    @PostMapping(value = "/queryByCondition")
    public CommonCurdResultBean<List<${entityName}>> queryByCondition(@RequestBody ${entityName} entity) {
        CommonCurdResultBean<List<${entityName}>> resultBean = new CommonCurdResultBean<>(true, "");
        resultBean.setObject((List<${entityName}>) ${objectName}Service.queryByCondition(entity));
        return resultBean;
    }

}